<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="机构名称" prop="nameorganization">
      <el-input v-model="dataForm.nameorganization" placeholder="机构名称"></el-input>
    </el-form-item>
    <el-form-item label="机构级别" prop="organizationlevel">
      <el-input v-model="dataForm.organizationlevel" placeholder="机构级别"></el-input>
    </el-form-item>
    <el-form-item label="阶段状态" prop="stagestate">
      <el-input v-model="dataForm.stagestate" placeholder="阶段状态"></el-input>
    </el-form-item>
    <el-form-item label="跟进状态" prop="followupstatus">
      <el-input v-model="dataForm.followupstatus" placeholder="跟进状态"></el-input>
    </el-form-item>
    <el-form-item label="经办人" prop="gestores">
      <el-input v-model="dataForm.gestores" placeholder="经办人"></el-input>
    </el-form-item>
    <el-form-item label="联系人" prop="contactperson">
      <el-input v-model="dataForm.contactperson" placeholder="联系人"></el-input>
    </el-form-item>
    <el-form-item label="审核状态" prop="auditstatus">
      <el-input v-model="dataForm.auditstatus" placeholder="审核状态"></el-input>
    </el-form-item>
    <el-form-item label="机构地址" prop="institutionaddress">
      <el-input v-model="dataForm.institutionaddress" placeholder="机构地址"></el-input>
    </el-form-item>
    <el-form-item label="手机" prop="phone">
      <el-input v-model="dataForm.phone" placeholder="手机"></el-input>
    </el-form-item>
    <el-form-item label="电话" prop="telephone">
      <el-input v-model="dataForm.telephone" placeholder="电话"></el-input>
    </el-form-item>
    <el-form-item label="国家" prop="country">
      <el-input v-model="dataForm.country" placeholder="国家"></el-input>
    </el-form-item>
    <el-form-item label="省份" prop="province">
      <el-input v-model="dataForm.province" placeholder="省份"></el-input>
    </el-form-item>
    <el-form-item label="市名" prop="cityname">
      <el-input v-model="dataForm.cityname" placeholder="市名"></el-input>
    </el-form-item>
    <el-form-item label="邮编" prop="postcode">
      <el-input v-model="dataForm.postcode" placeholder="邮编"></el-input>
    </el-form-item>
    <el-form-item label="网站" prop="website">
      <el-input v-model="dataForm.website" placeholder="网站"></el-input>
    </el-form-item>
    <el-form-item label="行业类别" prop="industrycategory">
      <el-input v-model="dataForm.industrycategory" placeholder="行业类别"></el-input>
    </el-form-item>
    <el-form-item label="" prop="importancelevel">
      <el-input v-model="dataForm.importancelevel" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="单位等级" prop="unitlevel">
      <el-input v-model="dataForm.unitlevel" placeholder="单位等级"></el-input>
    </el-form-item>
    <el-form-item label="区域等级" prop="regionalevel">
      <el-input v-model="dataForm.regionalevel" placeholder="区域等级"></el-input>
    </el-form-item>
    <el-form-item label="年费" prop="annualfee">
      <el-input v-model="dataForm.annualfee" placeholder="年费"></el-input>
    </el-form-item>
    <el-form-item label="电子资源经费" prop="electronicrfunding">
      <el-input v-model="dataForm.electronicrfunding" placeholder="电子资源经费"></el-input>
    </el-form-item>
    <el-form-item label="采购时间" prop="shoppingtime">
      <el-input v-model="dataForm.shoppingtime" placeholder="采购时间"></el-input>
    </el-form-item>
    <el-form-item label="采购级别" prop="purchaselevel">
      <el-input v-model="dataForm.purchaselevel" placeholder="采购级别"></el-input>
    </el-form-item>
    <el-form-item label="采购方式" prop="purchasingmethod">
      <el-input v-model="dataForm.purchasingmethod" placeholder="采购方式"></el-input>
    </el-form-item>
    <el-form-item label="采购途径" prop="procurementapproach">
      <el-input v-model="dataForm.procurementapproach" placeholder="采购途径"></el-input>
    </el-form-item>
    <el-form-item label="分配情况" prop="distribution">
      <el-input v-model="dataForm.distribution" placeholder="分配情况"></el-input>
    </el-form-item>
    <el-form-item label="商机提醒" prop="opportunityreminder">
      <el-input v-model="dataForm.opportunityreminder" placeholder="商机提醒"></el-input>
    </el-form-item>
    <el-form-item label="备注信息" prop="remarksinformation">
      <el-input v-model="dataForm.remarksinformation" placeholder="备注信息"></el-input>
    </el-form-item>
    <el-form-item label="添加标签" prop="addtag">
      <el-input v-model="dataForm.addtag" placeholder="添加标签"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          nameorganization: '',
          organizationlevel: '',
          stagestate: '',
          followupstatus: '',
          gestores: '',
          contactperson: '',
          auditstatus: '',
          institutionaddress: '',
          phone: '',
          telephone: '',
          country: '',
          province: '',
          cityname: '',
          postcode: '',
          website: '',
          industrycategory: '',
          importancelevel: '',
          unitlevel: '',
          regionalevel: '',
          annualfee: '',
          electronicrfunding: '',
          shoppingtime: '',
          purchaselevel: '',
          purchasingmethod: '',
          procurementapproach: '',
          distribution: '',
          opportunityreminder: '',
          remarksinformation: '',
          addtag: ''
        },
        dataRule: {
          nameorganization: [
            { required: true, message: '机构名称不能为空', trigger: 'blur' }
          ],
          organizationlevel: [
            { required: true, message: '机构级别不能为空', trigger: 'blur' }
          ],
          stagestate: [
            { required: true, message: '阶段状态不能为空', trigger: 'blur' }
          ],
          followupstatus: [
            { required: true, message: '跟进状态不能为空', trigger: 'blur' }
          ],
          gestores: [
            { required: true, message: '经办人不能为空', trigger: 'blur' }
          ],
          contactperson: [
            { required: true, message: '联系人不能为空', trigger: 'blur' }
          ],
          auditstatus: [
            { required: true, message: '审核状态不能为空', trigger: 'blur' }
          ],
          institutionaddress: [
            { required: true, message: '机构地址不能为空', trigger: 'blur' }
          ],
          phone: [
            { required: true, message: '手机不能为空', trigger: 'blur' }
          ],
          telephone: [
            { required: true, message: '电话不能为空', trigger: 'blur' }
          ],
          country: [
            { required: true, message: '国家不能为空', trigger: 'blur' }
          ],
          province: [
            { required: true, message: '省份不能为空', trigger: 'blur' }
          ],
          cityname: [
            { required: true, message: '市名不能为空', trigger: 'blur' }
          ],
          postcode: [
            { required: true, message: '邮编不能为空', trigger: 'blur' }
          ],
          website: [
            { required: true, message: '网站不能为空', trigger: 'blur' }
          ],
          industrycategory: [
            { required: true, message: '行业类别不能为空', trigger: 'blur' }
          ],
          importancelevel: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          unitlevel: [
            { required: true, message: '单位等级不能为空', trigger: 'blur' }
          ],
          regionalevel: [
            { required: true, message: '区域等级不能为空', trigger: 'blur' }
          ],
          annualfee: [
            { required: true, message: '年费不能为空', trigger: 'blur' }
          ],
          electronicrfunding: [
            { required: true, message: '电子资源经费不能为空', trigger: 'blur' }
          ],
          shoppingtime: [
            { required: true, message: '采购时间不能为空', trigger: 'blur' }
          ],
          purchaselevel: [
            { required: true, message: '采购级别不能为空', trigger: 'blur' }
          ],
          purchasingmethod: [
            { required: true, message: '采购方式不能为空', trigger: 'blur' }
          ],
          procurementapproach: [
            { required: true, message: '采购途径不能为空', trigger: 'blur' }
          ],
          distribution: [
            { required: true, message: '分配情况不能为空', trigger: 'blur' }
          ],
          opportunityreminder: [
            { required: true, message: '商机提醒不能为空', trigger: 'blur' }
          ],
          remarksinformation: [
            { required: true, message: '备注信息不能为空', trigger: 'blur' }
          ],
          addtag: [
            { required: true, message: '添加标签不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/com/business/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.nameorganization = data.business.nameorganization
                this.dataForm.organizationlevel = data.business.organizationlevel
                this.dataForm.stagestate = data.business.stagestate
                this.dataForm.followupstatus = data.business.followupstatus
                this.dataForm.gestores = data.business.gestores
                this.dataForm.contactperson = data.business.contactperson
                this.dataForm.auditstatus = data.business.auditstatus
                this.dataForm.institutionaddress = data.business.institutionaddress
                this.dataForm.phone = data.business.phone
                this.dataForm.telephone = data.business.telephone
                this.dataForm.country = data.business.country
                this.dataForm.province = data.business.province
                this.dataForm.cityname = data.business.cityname
                this.dataForm.postcode = data.business.postcode
                this.dataForm.website = data.business.website
                this.dataForm.industrycategory = data.business.industrycategory
                this.dataForm.importancelevel = data.business.importancelevel
                this.dataForm.unitlevel = data.business.unitlevel
                this.dataForm.regionalevel = data.business.regionalevel
                this.dataForm.annualfee = data.business.annualfee
                this.dataForm.electronicrfunding = data.business.electronicrfunding
                this.dataForm.shoppingtime = data.business.shoppingtime
                this.dataForm.purchaselevel = data.business.purchaselevel
                this.dataForm.purchasingmethod = data.business.purchasingmethod
                this.dataForm.procurementapproach = data.business.procurementapproach
                this.dataForm.distribution = data.business.distribution
                this.dataForm.opportunityreminder = data.business.opportunityreminder
                this.dataForm.remarksinformation = data.business.remarksinformation
                this.dataForm.addtag = data.business.addtag
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/com/business/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'nameorganization': this.dataForm.nameorganization,
                'organizationlevel': this.dataForm.organizationlevel,
                'stagestate': this.dataForm.stagestate,
                'followupstatus': this.dataForm.followupstatus,
                'gestores': this.dataForm.gestores,
                'contactperson': this.dataForm.contactperson,
                'auditstatus': this.dataForm.auditstatus,
                'institutionaddress': this.dataForm.institutionaddress,
                'phone': this.dataForm.phone,
                'telephone': this.dataForm.telephone,
                'country': this.dataForm.country,
                'province': this.dataForm.province,
                'cityname': this.dataForm.cityname,
                'postcode': this.dataForm.postcode,
                'website': this.dataForm.website,
                'industrycategory': this.dataForm.industrycategory,
                'importancelevel': this.dataForm.importancelevel,
                'unitlevel': this.dataForm.unitlevel,
                'regionalevel': this.dataForm.regionalevel,
                'annualfee': this.dataForm.annualfee,
                'electronicrfunding': this.dataForm.electronicrfunding,
                'shoppingtime': this.dataForm.shoppingtime,
                'purchaselevel': this.dataForm.purchaselevel,
                'purchasingmethod': this.dataForm.purchasingmethod,
                'procurementapproach': this.dataForm.procurementapproach,
                'distribution': this.dataForm.distribution,
                'opportunityreminder': this.dataForm.opportunityreminder,
                'remarksinformation': this.dataForm.remarksinformation,
                'addtag': this.dataForm.addtag
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
